package com.hdsx.restful.glzt.roadline.cdsl.rest;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import org.springframework.stereotype.Service;

import com.hdsx.restful.glzt.roadline.cdsl.bean.Cdsl;
import com.hdsx.restful.glzt.roadline.cdsl.service.CdslService;
import com.hdsx.restful.util.CheckEmpty;
import com.hdsx.restful.util.EasyUI;


@Path("/cdsl")
@Service
public class CdslRestServer {
	@Resource(name="cdslServiceImpl")
	private CdslService cdslService;

	/**
	 * http://192.168.0.103:8080/restful/rest/cdsl/list?lxdm=H65&page=0&rows=10
	 * @param lxdm
	 * @param page
	 * @param rows
	 * @return
	 */
	@GET
	@Path("/list")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Cdsl> queryList(@QueryParam("lxdm") String lxdm,@QueryParam("page") int page,@QueryParam("rows") int rows) {
		EasyUI<Cdsl> uiPage = new EasyUI<Cdsl>(page, rows);
		int count =cdslService.queryCountByParameter(lxdm);
		List<Cdsl> servicefws= cdslService.queryByParameter(lxdm,uiPage.getBegin(),uiPage.getEnd());
		uiPage.setTotal(count);
		uiPage.setRows(servicefws);
		return uiPage;
	}
	
	@GET
	@Path("/queryCdslString")
	@Produces(MediaType.APPLICATION_JSON)
	public String queryCdslString(@QueryParam("id") String id)
	{
		return cdslService.queryCdslString(id);
	}
	
	@GET
	@Path("/detail")
	@Produces(MediaType.APPLICATION_JSON)
	public EasyUI<Cdsl> detail(@QueryParam("xzqhbm") String xzqhbm,@QueryParam("cdsl")int cdsl,@QueryParam("page") int page,@QueryParam("rows") int rows){
		xzqhbm = CheckEmpty.subXzqhbm(xzqhbm);
		EasyUI<Cdsl> easyUI=new EasyUI<Cdsl>(page,rows);
		Map<String,Object> map = easyUI.getParameter();
		map.put("xzqhbm", xzqhbm);
		map.put("cdsl", cdsl);
		List<Cdsl> lists=cdslService.queryDetail(map);
		int total = cdslService.countDetail(map);
		easyUI.setRows(lists);
		easyUI.setTotal(total);
		return easyUI;
	}
	
}
